<?php

/**
 * 账本 - 商户分账绑定查询功能使用示例
 */

require_once __DIR__ . '/../../../vendor/autoload.php';

use JLPay\Core\OrgConfig;
use JLPay\Core\DemoConfig;
use JLPay\Services\Ledger\Merchconf\MerchconfService;
use JLPay\Models\Ledger\Merchconf\MerchRevBindQueryRequest;
use JLPay\Utils\Logger;
use JLPay\Utils\DemoRequestHandler;

// =================== 日志配置 =====================
$logger = Logger::getInstance();

// =================== 工具函数 =====================
function createConfig(): OrgConfig
{
    return DemoConfig::createConfig();
}

// =================== 数据构建函数 =====================
function buildMerchRevBindQueryRequest(): MerchRevBindQueryRequest
{
    $request = new MerchRevBindQueryRequest();
    
    // 设置请求参数
    $request->setOrgCode("50720711")
            ->setMchId("849581183510017")
            ->setRevMchId("849584307420004");
    
    return $request;
}

// =================== 示例函数 =====================
function merchRevBindQueryDemo(): void
{
    global $logger;
    
    $logger->info("开始执行商户分账绑定查询示例");
    
    // 创建配置对象和商户配置服务
    $config = createConfig();
    $merchconfService = new MerchconfService($config);
    
    // 创建商户分账绑定查询请求
    $request = buildMerchRevBindQueryRequest();
    
    // 发送请求 - 使用DemoRequestHandler
    $response = DemoRequestHandler::sendRequestAndHandleResponse(
        $merchconfService, 
        $request, 
        "商户分账绑定查询",
        function($service, $request) {
            return $service->queryMerchRevBind($request);
        }
    );

    // 处理响应结果
    if ($response) {
        $logger->info("响应报文：" . json_encode($response->toArray(), JSON_UNESCAPED_UNICODE));
    }
}

// =================== 主程序 =====================
$logger->info("=" . str_repeat("=", 50));
$logger->info("===== 商户分账绑定查询示例 开始 =====");
$logger->info("=" . str_repeat("=", 50));

merchRevBindQueryDemo();

$logger->info("=" . str_repeat("=", 50));
$logger->info("===== 商户分账绑定查询示例执行完毕 =====");
$logger->info("=" . str_repeat("=", 50)); 